/*
 * 子账号管理
 */
(function() {
	function can_manage_employees(argument) {
		return this.getPerm().can_manage_employees;
	};
	var skill = {
		canEmployees: can_manage_employees,
		_getEmployees: function(employees_id) {
			var employees = BusEmployeesCon.get(employees_id);
			if (!employees) {
				throwCusError("找不到指定子账号")
			}
			if (employees.bus_id !== this._id) {
				throwCusError("指定子账号不属于商家")
			}
			return employees;
		},
		//新增划分子账号
		addEmployees: function(employees_info) {
			employees_info.bus_id = this._id;
			var employees = new BusEmployeesCon(employees_info);
			return employees;
		},
		//修改子账号信息
		updateEmployees: function(employees_id, employees_info) {
			var employees = this._getEmployees(employees_id);
			employees.setInfo(employees_info);
			return employees;
		},
		removeEmployees: function(employees_id) {
			var employees = this._getEmployees(employees_id);
			employees.destroy();
		},
		getEmployeesList: function() {
			return BusEmployeesCon.findByBusId(this._id);
		},
		loginEmployees: function(login_info) {
			var maybey_emp;
			if (!this.getEmployeesList().some(function(employee) {
					maybey_emp = employee;
					return employee.name == login_info.name;
				})) {
				throwCusError("找不到指定员工账号")
			}
			if (!maybey_emp.checkPassword(login_info.pwd)) {
				throwCusError("员工登录密码错误")
			}else{
				return maybey_emp;
			}
		}
	};
	module.exports = skill;
	var db = require("../db/index");
	var BinaCon = require("../bina/_con");
	var DomainCon = require("../domain/_con");
	var GoodsCon = require("../goods/_con");
	var UserCon = require("../user/_con");
	var BusCon = require("../bus/_con");
	var AchCon = require("../ach/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var LeagueCon = require("../league/_con");
	var BuffCon = require("../buff/_con");
	var BusUserBindCon = require("../bus_user_bind/_con");
	var BusGuideCon = require("../bus.guide/_con");
	var BusEmployeesCon = require("../bus.employees/_con");
	var CommentCon = require("../comment/_con");
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var helper = require("../_include/helper");
	var md5 = require("../_include/md5");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
	var tld = require('tldjs');
	var fs = require("fs");
	var Fiber = require('fibers');
	var midEvent = require("../../middleware/index");
}());